﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using Sinacor.Infra.Service.Security.Licensing.Infra.Security.Licensing;
using Sinacor.Infra.Service.Security.Services;
using Sinacor.Infra.Service.Security.Authorization;
using PSE.Framework.ProviderLoader.Configuration;
using PSE.Framework.ProviderLoader;
using PSE.Framework.Common.Security.Services.Configuration;

namespace Sinacor.Infra.Service.Security.Licensing
{
    public class LicensingProvider : BaseProvider, ILicensingProvider
    {
        public LicensingProvider(ProviderConfigurationElement configuration)
            : base(configuration)
        {

        }

        #region ILicensingProvider Members

        public byte[] GetLicesingFromServer()
        {
            byte[] result;

            using (ServiceInstance<ILicensing> si = new ServiceInstance<ILicensing>())
            {
                ILicensing service = si.TryGetInstance(
                                AuthorizationContext.Current.LoginName,
                                AuthorizationContext.Current.Password,
                                AuthorizationContext.Current.CompanyId,
                                AuthorizationContext.Current.SessionId,
                                AuthorizationContext.Current.TokenId,
                                AuthorizationContext.Current.SessionExpires, CriptographyLevelType.Federated);

                result = service.GetLincensing().BinaryLicense;
            }

            return result;
        }

        #endregion
    }
}
